-
Notifications
You must be signed in to change notification settings - Fork 48
Implement guided generation for SystemLanguageModel
#59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements guided generation for SystemLanguageModel, enabling structured output generation using schema-based constraints. The implementation adds support for generating strongly-typed Swift structs from natural language prompts by converting GenerationSchema to FoundationModels' schema format and handling both streaming and non-streaming responses.
Key Changes:
- Added schema-based generation support for non-String types using FoundationModels' schema APIs with proper $defs dependency extraction
- Implemented partial JSON decoding with fallback to placeholder content for graceful error recovery
- Refactored ResponseStream to use fallbackSnapshot pattern instead of storing concrete content values
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/AnyLanguageModel/Models/SystemLanguageModel.swift | Core implementation of guided generation with schema conversion, streaming support, and placeholder fallback logic |
| Tests/AnyLanguageModelTests/SystemLanguageModelTests.swift | Comprehensive test suite covering simple structs, nested structures, arrays, enum constraints, and streaming |
| Sources/AnyLanguageModel/LanguageModelSession.swift | Refactored ResponseStream to use optional fallbackSnapshot for cleaner handling of streaming vs non-streaming cases |
| Sources/AnyLanguageModel/GenerationSchema.swift | Made defs property accessible to support schema resolution in SystemLanguageModel |
| Sources/AnyLanguageModel/Generable.swift | Enhanced asPartiallyGenerated() with safer conversion logic and fallback to generatedContent reconstruction |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1fa983e to
679e9d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Related to #27